﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using Project.dalSql;
using System.Web.SessionState;
using WISD.Common;

namespace WISD.CarFriend.Web.Admin.Control
{
    /// <summary>
    /// MemberCard 的摘要说明
    /// 继承IReadOnlySessionState，就可以使用Session
    /// </summary>
    public class MemberCard : IHttpHandler, IReadOnlySessionState
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string MemberCardID = NullHelper.NullProcess<string>(context.Request["MemberCardID"], "");
            string MemberID = NullHelper.NullProcess<string>(context.Request["MemberID"], "");
            string MemberLevel = NullHelper.NullProcess<string>(context.Request["MemberLevel"], "-1");
            string AdmissionDate = NullHelper.NullProcess<string>(context.Request["AdmissionDate"], "1888/1/1");
            string ExpirationDate = NullHelper.NullProcess<string>(context.Request["ExpirationDate"], "1888/1/1");
            string Pwd = NullHelper.NullProcess<string>(context.Request["Pwd"], "");
            string ResidualAmount = NullHelper.NullProcess<string>(context.Request["ResidualAmount"], "0");
            string State = NullHelper.NullProcess<string>(context.Request["State"], "-1");
            string Reviser = context.Session["UserCode"].ToString();

            string action = NullHelper.NullProcess<string>(context.Request["Action"], "");
            int pageSize = NullHelper.NullProcess<int>(context.Request["PageSize"], 0);
            int pageIndex = NullHelper.NullProcess<int>(context.Request["CurrentPage"], 0);
            string condition = NullHelper.NullProcess<string>(context.Request["Condition"], "");
            string main = NullHelper.NullProcess<string>(context.Request["Main"], "");

            if (action == "Init")
            {
                context.Response.Write(BLL.OA.MemberCardModule.GetData(pageSize, pageIndex, condition));
                context.Response.End();
            }

            if (action == "GetOne")
            {
                context.Response.Write(BLL.OA.MemberCardModule.GetOne(main));
                context.Response.End();
            }

            if (action == "AddEntity")
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                dictionary.Add("MemberCardID", MemberCardID);
                dictionary.Add("MemberID", MemberID);
                dictionary.Add("MemberLevel", MemberLevel);
                dictionary.Add("AdmissionDate", AdmissionDate);
                dictionary.Add("ExpirationDate", ExpirationDate);
                dictionary.Add("Pwd", Pwd);
                dictionary.Add("ResidualAmount", ResidualAmount);
                dictionary.Add("State", State);
                dictionary.Add("Reviser", Reviser);
                dictionary.Add("ReviseDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                if (BLL.OA.MemberCardModule.AddEntity(dictionary).Equals("Success"))
                {

                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "DeleteEntity")
            {
                context.Response.Write(BLL.OA.MemberCardModule.DeleteEntity(main));
                context.Response.End();
            }

            if (action == "EditEntity")
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                dictionary.Add("MemberCardID", MemberCardID);
                dictionary.Add("MemberID", MemberID);
                dictionary.Add("MemberLevel", MemberLevel);
                dictionary.Add("AdmissionDate", AdmissionDate);
                dictionary.Add("ExpirationDate", ExpirationDate);
                dictionary.Add("Pwd", Pwd);
                dictionary.Add("ResidualAmount", ResidualAmount);
                dictionary.Add("State", State);
                dictionary.Add("Reviser", Reviser);
                dictionary.Add("ReviseDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                if (BLL.OA.MemberCardModule.EditEntity(dictionary).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "GetMemberData")
            {
                context.Response.Write(BLL.OA.MemberCardModule.GetMemberData(pageSize, pageIndex, condition));
                context.Response.End();
            }

            if (action == "LoadMemberCardType")
            {
                context.Response.Write(BLL.OA.MemberCardModule.LoadMemberCardType());
                context.Response.End();
            }

            if (action == "GetMemberConsumeItem")
            {
                context.Response.Write(BLL.OA.MemberCardModule.GetMemberConsumeItem(pageSize, pageIndex, condition));
                context.Response.End();
            }
        }


        /// <summary>
        /// IsReusable
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }


    }
}